home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / maximus / mul100.zip / EXPRPT.SCR < prev    next >
Text File  |  1993-02-01  |  6KB  |  184 lines

  1.  
  2. // EXPRPT.SCR  --  Maximus-CBCS User Expiry Reporter  --  Version 1.01
  3. //
  4. // Script program for MUL - the Maximus User Language
  5. // MUL is (C) Copyright 1990-93 by CodeLand Australia
  6. //
  7. // ExpRpt writes an account expiry text file report. This script is
  8. // based on the EXPRPT executable included in the UEDit v2.01 archive,
  9. // originally written for Brian Wendt of 3:640/205. This is a slightly
  10. // simplified version, to provide as clear an example of report writing
  11. // as possible. Specifically the ascii delimited output format option
  12. // is not supported in this script.
  13. //
  14. // USAGE:       MUL -pExpRpt [ /# ]
  15. //
  16. //              /P<#>        Paginate report to # lines per page
  17. //              /E           Report expiry records only
  18.  
  19. char *banner="EXPRPT v1.01";                // Script banner
  20. char *desc="Maximus User Expiry Reporter";  // Description
  21. char *ufile = "USER.BBS";                   // User file path and name
  22. char *rptfile = "EXPRPT.RPT";               // Report file path and name
  23.  
  24. int page=0;                                 // Paginate lines per page
  25. long rp=NULL;                               // Report file file handle
  26. int expiry_only=0;                          // Report Expiry records only flag
  27.  
  28. main (int argc, char *arg1, char *arg2)     // Main program
  29. {
  30.     int i, count=1, page_num=1;
  31.     char *p, back[10], exp[40];
  32.  
  33.     printf ("\n%s - %s\n",banner,desc);     // Announce
  34.     getcmdline (argc,arg1,arg2);            // Get the command line
  35.  
  36.     sprintf (back,"%c%c%c%c",8,8,8,8);      // Notify setup
  37.  
  38.     // Open user file
  39.     if (!BaseOpenR (ufile)) {
  40.         printf ("\nERROR opening user file %s\n",ufile);
  41.         saybibi (); exit ();
  42.     }
  43.  
  44.     // Open report file
  45.     if ((rp=fopen (rptfile,"w"))==NULL) {
  46.         printf ("\nERROR opening report file %s\n",rptfile);
  47.         BaseClose (); saybibi (); exit ();
  48.     }
  49.  
  50.     printf ("\nWriting report file \"%s\"\n\n",rptfile);
  51.  
  52.     // Sort the records
  53.     BaseSort (IDX_LNAME);                   // Sort by last name ascending
  54.  
  55.     printf ("Processing record 0001");      // Notify
  56.     prt_hdr (page_num++);                   // Output page header
  57.  
  58.     for (i=2;i<=BaseCount ();++i) {         // For all records except Sysop
  59.         if(!BaseRead (i)) break;            // Read record, abort on error
  60.  
  61.         if (!(i%10))                        // Notify
  62.             printf ("%s%04u",back,i);
  63.  
  64.         if (have_expiry ()) {               // Only report expiry records
  65.             fprintf (rp,"%-30s %s %s %s\n", // Output data
  66.                 USRname,
  67.                 DateToStr (USRludate),
  68.                 BasePrivStr (USRpriv),
  69.                 get_expiry (exp)
  70.             );
  71.  
  72.             if(page && ++count>page) {      // Check paging
  73.                 fprintf (rp,"%c",0x0C);     // Page feed
  74.                 prt_hdr (page_num++);       // Output page header
  75.                 count=1;
  76.             }
  77.         }
  78.     }
  79.  
  80.     if (page) fprintf (rp,"%c",0x0C);       // Final page feed
  81.     printf ("%s%04u\n",back,i);             // Notify cleanup
  82.  
  83.     fclose (rp);                            // Close report file
  84.     BaseClose ();                           // Close the user base
  85.  
  86.     saybibi ();                             // Was it good for you too?
  87. }
  88.  
  89. prt_hdr (int page_num)                      // Output a page header
  90. {
  91.     fprintf (rp,"\n                             ACCOUNT EXPIRY REPORT                    %s\n",
  92.         DateToStr (SysDate ()));
  93.  
  94.     fprintf (rp,"                             ---------------------\n");
  95.     if (page) fprintf (rp,"                                                                      Page %3u\n",page_num);
  96.     else fprintf (rp,"\n");
  97.     fprintf (rp,"--------------------------------------------------------------------------------\n");
  98.     fprintf (rp,"Name                           LastCall Access    Expy Value    Action Demote\n");
  99.     fprintf (rp,"------------------------------ -------- --------- ---- -------- ------ ---------\n");
  100. }
  101.  
  102. have_expiry ()                              // Return expiry status
  103. {
  104.     return !expiry_only || (And (USRxpflag,XP_DATE) || And (USRxpflag,XP_TIME));
  105. }
  106.  
  107. get_expiry (char *str)                      // Build Expiry information string
  108. {
  109.     char buf[20];
  110.  
  111.     // Get the Expiry type string
  112.     strcpy (str,BaseXpTypStr (USRxpflag));
  113.  
  114.     if (USRxpflag == XP_NONE) return str;   // Allows a quick exit
  115.  
  116.     // Get the expiry type data
  117.     if (And (USRxpflag,XP_DATE)) {
  118.         strcat (str," "); strcat (str,DateToStr (USRxpdate));
  119.  
  120.         // Get the expiry action string
  121.         strcat (str," "); strcat (str,BaseXpActStr (USRxpflag));
  122.  
  123.         // Get the expiry action data
  124.         if (And (USRxpflag,XP_DEMOTE)) {
  125.             strcat (str," "); strcat (str,BasePrivStr (USRxppriv));
  126.         }
  127.     }
  128.     else if (And (USRxpflag,XP_TIME)) {
  129.         sprintf (buf,"%8lu",USRxpmins);
  130.         strcat (str," "); strcat (str,buf);
  131.  
  132.         // Get the expiry action string
  133.         strcat (str," "); strcat (str,BaseXpActStr (USRxpflag));
  134.  
  135.         // Get the expiry action data
  136.         if (And (USRxpflag,XP_DEMOTE)) {
  137.             strcat (str," "); strcat (str,BasePrivStr (USRxppriv));
  138.         }
  139.     }
  140.  
  141.     return str;
  142. }
  143.  
  144. // Get the command line
  145. getcmdline (int argc, char *arg1, char *arg2)           
  146. {
  147.     if (argc) {
  148.         if (arg1[0] == '/') {
  149.             if (arg1[1] == 'p' || arg1[1] == 'P') {
  150.                 page=atoi (arg1+2);
  151.                 if (!page) page=55;
  152.             }
  153.             else if (arg1[1] == 'e' || arg1[1] == 'E') {
  154.                 ++expiry_only;
  155.             }
  156.         }
  157.     }
  158.     if (argc>1) {
  159.         if (arg2[0] == '/') {
  160.             if (arg2[1] == 'p' || arg2[1] == 'P') {
  161.                 page=atoi (arg2+2);
  162.                 if (!page) page=55;
  163.             }
  164.             else if (arg2[1] == 'e' || arg2[1] == 'E') {
  165.                 ++expiry_only;
  166.             }
  167.         }
  168.     }
  169.  
  170.     if (page) {
  171.         if (page<8) page=1;
  172.         else page=page-7;
  173.     }
  174. }
  175.  
  176. // Byebye
  177. saybibi ()
  178. {                             
  179.     puts ("\nExpRpt done!\n");
  180. }
  181.  
  182. // End of script
  183.  
  184.